package com.zc.mychart.chart;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.renderer.scatter.IShapeRenderer;
import com.github.mikephil.charting.utils.ViewPortHandler;

/**
 * Custom shape renderer that draws a single line.
 * Created by philipp on 26/06/16.
 */
public class CustomScatterShapeRenderer implements IShapeRenderer {


    public String drawText;

    public CustomScatterShapeRenderer(String drawText) {
        this.drawText = drawText;
    }

    @Override
    public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                            float posX, float posY, Paint renderPaint) {

        final float shapeHalf = dataSet.getScatterShapeSize() / 2f;


        c.drawRect(posX - shapeHalf,
                posY - shapeHalf,
                posX + shapeHalf,
                posY + shapeHalf,
                renderPaint);


        renderPaint.setColor(Color.parseColor("#FC7A34"));
        renderPaint.setAntiAlias(true);
        renderPaint.setTextSize(24);

        Paint.FontMetrics fontMetrics = renderPaint.getFontMetrics();
        float y = (Math.abs(fontMetrics.ascent) - fontMetrics.descent) / 2;

        float width = renderPaint.measureText(drawText);

        c.drawText(drawText, posX - ( width / 2 ),posY + y  , renderPaint);


//        c.drawLine(
//                posX - shapeHalf,
//                posY - shapeHalf,
//                posX + shapeHalf,
//                posY + shapeHalf,
//                renderPaint);
    }
}
